package com.shanks.framework.mq.repository;

import com.shanks.framework.mq.enums.MessageRecordStatusEnum;
import com.shanks.framework.mq.model.MessageRecordPO;

import java.util.Date;
import java.util.List;


public interface MessageRecordRepository {
    /**
     * 更新消息状态
     *
     * @param messageId
     * @param oldMessageStatus
     * @param newMessageStatus
     * @return
     */
    Boolean updateMessageStatus(Long messageId, MessageRecordStatusEnum oldMessageStatus,
                                MessageRecordStatusEnum newMessageStatus);

    /**
     * 更新消息重试次数
     *
     * @param messageId
     * @param retryCount
     */
    void updateMessageRetryCount(Long messageId, int retryCount);

    /**
     * 更新消息状态
     *
     * @param messageUuid
     * @param oldMessageStatus
     * @param newMessageStatus
     * @param consumeClientSource
     * @return
     */
    Boolean updateMessageStatusByUuid(String messageUuid, MessageRecordStatusEnum oldMessageStatus,
                                      MessageRecordStatusEnum newMessageStatus, Date updateTime, String consumeClientSource);

    void insert(MessageRecordPO messageRecordPO);

    void insertBatch(List<MessageRecordPO> messageRecordPOList);

    /**
     * 时间范围分页查询pending状态消息
     *
     * @param createTimeStart
     * @param createTimeEnd
     * @param pageSize
     * @param pageIndex
     * @param producerKeys
     * @return
     */
    List<MessageRecordPO> selectPendingMessageList(Date createTimeStart, Date createTimeEnd, int pageSize, int pageIndex, List<String> producerKeys);

    /**
     * 时间范围分页查询sending状态消息
     *
     * @param createTimeStart
     * @param sendingTimeEnd
     * @param pageSize
     * @param pageIndex
     * @param producerKeys
     * @return
     */
    List<MessageRecordPO> selectSendTimeoutMessageList(Date createTimeStart, Date sendingTimeEnd, int pageSize, int pageIndex, List<String> producerKeys);

    /**
     * 时间范围分页查询sent状态消息
     *
     * @param createTimeStart
     * @param sentTimeEnd
     * @param pageSize
     * @param pageIndex
     * @param ackCheckingTopics
     * @return
     */
    List<MessageRecordPO> selectAckTimeoutMessageList(Date createTimeStart, Date sentTimeEnd, int pageSize, int pageIndex, List<String> producerKeys, List<String> ackCheckingTopics);
}
